// pages/orders/orders.js
Page({
  data: {
    current: 0,
    orderList: [],
    completedOrderList: []
  },

  onLoad() {
    // 模拟接口获取数据
    this.fetchOrderList()
  },

  fetchOrderList() {
    // 假设接口返回的数据如下
    const orderList = [
      {
        orderNo: "123456",
        status: "未完成",
        address: "地址1"
      },
      {
        orderNo: "789012",
        status: "未完成",
        address: "地址2",

      },
      {
        orderNo: "7222012",
        status: "未完成",
        address: "地址3",
     
      },
      // 更多订单数据...
    ]

    this.setData({
      orderList: orderList
    })
  },

  onClick(event) {
    var index = event.currentTarget.dataset.id;
    this.setData({
      current: index
    });
  },

  completeOrder(event) {
    var index = event.currentTarget.dataset.index;
    var orderList = this.data.orderList;
    var completedOrderList = this.data.completedOrderList;

    var completedOrder = orderList[index];
    completedOrderList.push(completedOrder);

    wx.showModal({
      title: '确认完成',
      content: '确定要标记该订单为已完成吗？',
      success: (res) => {
        if (res.confirm) {
          orderList.splice(index, 1);

          this.setData({
            orderList: orderList,
            completedOrderList: completedOrderList
          });
        }
      }
    });
  }
});